﻿/*******************************************************
Use this dialog to replace browser's default alert\confirm.

var window = new CloudDisk.Window('content', 'title');
window.show();

*******************************************************/

CloudDisk.Window = function (config) {
    var el = $('<div class="content-window"></div>');
    var that = this;
    el.html([
	    '<div class="window-head">',
		    '<div class="window-title"></div>',
			'<div class="window-btn btn-close"></div>',
		'</div>',
        '<div class="window-body"></div>'
	].join(''));
    el.appendTo(document.body);

    el.find('.window-body').html(config.content);
    el.find('.window-title').html(config.title);
	el.css('width', config.width? config.width: 600);
	el.find('.window-body').css('height', config.height? config.height: 450);
	el.find('.btn-close').click(function(){
	    that.close();
	});
    that.el = el;
	
	$(window).bind('resize', function(){
	    that.position();
	});
};

CloudDisk.Window.prototype = {
	
	position: function(e){
	    var el = this.el;
        el.css('left', ($(window).width() - el.width()) / 2 + 'px');
        el.css('top', ($(window).height() - el.height()) / 2 + 'px');
	},

    open: function (){ 
	    CloudDisk.Util.showMask();
        this.el.show();
        this.position();
    },
    close: function () {
        this.el.hide();
        CloudDisk.Util.hideMask();
    }
};